home *** CD-ROM | disk | FTP | other *** search
- program tstbufst;
-
- {$IFDEF Win32}
- {$APPTYPE CONSOLE}
- {$ENDIF}
-
- uses
- {$IFDEF Windows}
- WinCrt,
- WinTypes, WinProcs,
- {$ELSE}
- Windows,
- {$ENDIF}
- Classes,
- BUFFSTRM;
-
- type
- PBlock = ^TBlock;
- TBlock = array [0..8191] of byte;
-
- var
- StartChar : char;
- BytesInBlock : integer;
- Block : PBlock;
-
-
- procedure WriteBlock(S : TStream);
- begin
- FillChar(Block^, BytesInBlock, StartChar);
- inc(StartChar);
- S.Write(Block^, BytesInBlock);
- end;
-
- procedure ReadCheckBlock(S : TStream);
- var
- i : integer;
- begin
- S.Read(Block^, BytesInBlock);
- for i := 0 to pred(BytesInBlock) do
- if (Block^[i] <> ord(StartChar)) then
- writeln('ERROR at byte ', i);
- inc(StartChar);
- end;
-
- var
- S : TStream;
- i : longint;
- StartTime : longint;
-
- begin
- BytesInBlock := 40;
- GetMem(Block, BytesInBlock);
- try
- writeln('creating the file stream');
- S := TbfsBufferedFileStream.Create('Test', fmCreate, 4096);
- {S := TFileStream.Create('Test', fmCreate);}
- try
- StartTime := GetTickCount;
- writeln('writing blocks');
- StartChar := 'A';
- for i := 0 to 159999 do
- WriteBlock(S);
- writeln('seek to start');
- S.Seek(0, soFromBeginning);
- writeln('readin/checking blocks');
- StartChar := 'A';
- for i := 0 to 159999 do
- ReadCheckBlock(S);
- writeln('readin/checking blocks in reverse order');
- S.Seek(0, soFromEnd);
- for i := 0 to 159999 do begin
- S.Seek(-BytesInBlock, soFromCurrent);
- dec(StartChar);
- ReadCheckBlock(S);
- S.Seek(-BytesInBlock, soFromCurrent);
- dec(StartChar);
- end;
- writeln('Time taken: ', GetTickCount-StartTime);
- finally
- S.Destroy;
- end;
- writeln('done');
- readln;
- finally
- FreeMem(Block, BytesInBlock);
- end;
- end.
-